<?php defined('SYSPATH') OR die('No Direct Script Access');

Class Controller_Products extends Controller_SecureTemplate {
	
	public function action_index()
	{
		$this->template->title = 'Producten';
		$view = new View('pages/products');
		
		$model_product = new Model_Product();
		$result = $model_product->select_all_products();
		if (isset($result['products']))
		{
			$view->bind("products", $result['products']);
		}
		else 
		{
			$view->bind("products", $result);
		}
		$this->template->content = $view;
	}
	
	/**
	 * Function to add a product to the grocerylist
	 */
	public function action_addtolist() 
	{
		if(isset($_GET['id']))
		{
			$grocery_list_id = $this->session->get('grocery_list_id');
			$model_grocery_list = new Model_Grocerylist();
			$model_grocery_list->add_to_list($grocery_list_id, $_GET['id'], 1);
		}
	}
}